import {MenuDataItem} from "@ant-design/pro-layout";
import menus from "../../config/menu";
import checkAccess from "@/access/checkAccess";

/**
 * 获取有权限可访问的菜单
 * @param loginuser
 * @param menuItems
 */
const getAccessableMenus = (loginUser: API.LoginUserVO, menuItems: MenuDataItem[] = menus) => {
    return menuItems.filter((item:MenuDataItem):boolean => {
        if (!checkAccess((loginUser, item.access))){
            return false;
        }
        if (item.children){
            item.children = getAccessableMenus(loginUser, item.children)
        }
        return true;
    })


}
export default getAccessableMenus;
